cd "C:\Users\marku\Dropbox\AP Katrin Markus\replication"

use "Demokratieradar Welle 8.dta", clear

*** Socio demographics and background variables
clonevar age=Q3A1 
keep if age>15 // drop voters under 16
clonevar region=Q4
clonevar edu5cats=Q5
clonevar polint=Q10 if Q10<5 // Recode political interest
clonevar media=Q11 if Q11<7 // Recode media use
revrs media, replace
revrs polint, replace
recode Q56A1-Q56A6 (.=0)
gen know1=(Q56A1==1&Q56A4==1) //knows that ÖVP and Greens in national govt
gen know2=(Q58A1==4)
gen knowsum=know1+know2 // Knowledge scale
alpha polint media know1 know2, gen(soph) // sophistication scale
clonevar gender=Q1
gen male=(Q1==1)
gen lrself=Q74 if Q74<11 // Recode lr self-placement

*** party ID
gen ovpid=(Q20==1)
gen spoid=(Q20==2)
gen fpoid=(Q20==3)
gen othid=(Q20>3&Q20<10)
gen noid=(Q19==2)|(Q19==3)|(Q20==10)|(Q18==3)

gen id1=(ovpid==1)
gen id2=(spoid==1)
gen id3=(fpoid==1)

gen idcat=.
replace idcat=1 if ovpid==1
replace idcat=2 if spoid==1
replace idcat=3 if fpoid==1
replace idcat=4 if othid==1
replace idcat=5 if noid==1

clonevar idstrength_classic=Q21 if Q21<4
revrs idstrength_classic
clonevar idstrengtha=Q22 if Q22<5
revrs idstrengtha
clonevar idstrengthb=Q23 if Q23<5
revrs idstrengthb
alpha idstrength_classic idstrengtha idstrengthb, gen(idstrength_sum)



gen spovote=(Q17==2)
gen fpovote=(Q17==3)
gen ovpvote=(Q17==1)
gen othvote=(Q17>3&Q17<9)
gen novote=(Q17==9|Q17==10|Q17==11)

gen vote1=(ovpvote==1)
gen vote2=(spovote==1)
gen vote3=(fpovote==1)


gen votecat=.
replace votecat=1 if ovpvote==1
replace votecat=2 if spovote==1
replace votecat=3 if fpovote==1
replace votecat=4 if othvote==1
replace votecat=5 if novote==1

gen idvotecat=idcat
replace idvotecat=votecat if idcat==5&votecat!=.
replace idstrength_sum=0 if idcat==5&idvotecat<5
label define id 1 "ÖVP" 2 "SPÖ" 3 "FPÖ" 4 "OTH" 5 "NO"
label value idvotecat id

tabulate idvotecat, gen(idvotecat)

gen spopp=(pp==2)
gen fpopp=(pp==3)
gen ovppp=(pp==1)
gen othpp=(pp>3&pp<7)

gen ppc1=(ovppp==1)
gen ppc2=(spopp==1)
gen ppc3=(fpopp==1)



*** Experimental analysis

encode treat, gen(treatnum)
gen treat3=0 if treatnum==7
replace treat3=1 if treatnum==1|treatnum==2
replace treat3=2 if treatnum==3|treatnum==4
replace treat3=3 if treatnum==5|treatnum==6

label define treat3 0 "Ctrl" 1 "SP-OP" 2 "OP-FP" 3 "SP-FP"
label value treat3 treat3

gen personal=0 if treatnum==7
replace personal=2 if treatnum==2|treatnum==4|treatnum==6
replace personal=1 if treatnum==1|treatnum==3|treatnum==5
label define personal 0 "Ctrl" 1 "No prsnl" 2 "Prsnl"
label values personal personal


*** MANIPULATION CHECK
gen prob_o_s=Q27 if Q27!=.
replace prob_o_s=Q30 if Q30!=.
replace prob_o_s=Q54A1 if Q54A1!=.
gen prob_o_f=Q33 if Q33!=.
replace prob_o_f=Q36 if Q36!=.
replace prob_o_f=Q54A2 if Q54A2!=.
gen prob_s_f=Q39 if Q39!=.
replace prob_s_f=Q42 if Q42!=.
replace prob_s_f=Q54A3 if Q54A3!=.

gen like_o_s=Q28 if Q28!=.
replace like_o_s=Q31 if Q31!=.
replace like_o_s=Q55A1 if Q55A1!=.
gen like_o_f=Q34 if Q34!=.
replace like_o_f=Q37 if Q37!=.
replace like_o_f=Q55A2 if Q55A2!=.
gen like_s_f=Q40 if Q40!=.
replace like_s_f=Q43 if Q43!=.
replace like_s_f=Q55A3 if Q55A3!=.

*** Appendix H (Table H1): t-tests comparing perceived likelihood of coalitions

ttest prob_o_s if treat3==1|treat3==0,by(treat3)
ttest prob_o_f if treat3==2|treat3==0,by(treat3)
ttest prob_s_f if treat3==3|treat3==0,by(treat3)


** Placebo coalition probability perceptions
ttest prob_o_s if treatnum==1|treatnum==7,by(treatnum)
ttest prob_o_s if treatnum==2|treatnum==7,by(treatnum)
ttest prob_o_f if treatnum==3|treatnum==7,by(treatnum)
ttest prob_o_f if treatnum==4|treatnum==7,by(treatnum)
ttest prob_s_f if treatnum==5|treatnum==7,by(treatnum)
ttest prob_s_f if treatnum==6|treatnum==7,by(treatnum)



ttest like_o_s if treat3==1|treat3==0,by(treat3)
ttest like_o_f if treat3==2|treat3==0,by(treat3)
ttest like_s_f if treat3==3|treat3==0,by(treat3)

***Placebos
ttest prob_o_s if treat3==2|treat3==0,by(treat3)
ttest prob_o_s if treat3==3|treat3==0,by(treat3)

ttest prob_o_f if treat3==1|treat3==0,by(treat3)
ttest prob_o_f if treat3==3|treat3==0,by(treat3)

ttest prob_s_f if treat3==1|treat3==0,by(treat3)
ttest prob_s_f if treat3==2|treat3==0,by(treat3)


*** EXPERIMENTAL ANALYSIS

** Like-dislike scores
gen partylike1=Q46A1 if Q46A1!=.
replace partylike1=Q51A1 if Q51A1!=.
gen partylike2=Q46A2 if Q46A2!=.
replace partylike2=Q51A2 if Q51A2!=.
gen partylike3=Q46A3  if Q46A3!=.
replace partylike3=Q51A3 if Q51A3!=.


*** Left-right positions and distance
gen partylr1=Q49A1 if Q49A1!=.&Q49A1<11

replace partylr1=Q50A1 if Q50A1!=.&Q50A1<11

gen partylr2=Q49A2 if Q49A2!=.&Q49A2<11

replace partylr2=Q50A2 if Q50A2!=.&Q50A2<11
gen partylr3=Q49A3  if Q49A3!=.&Q49A3<11
replace partylr3=Q50A3 if Q50A3!=.&Q50A3<11

gen partydist1=abs(lrself-partylr1)
gen partydist2=abs(lrself-partylr2)
gen partydist3=abs(lrself-partylr3)

gen partyconvergelr1=abs(partylr1-partylr2)
gen partyconvergelr2=abs(partylr1-partylr3)
gen partyconvergelr3=abs(partylr2-partylr3)

gen partyconv12=abs(partylr1-partylr2) 
gen partyconv13=abs(partylr1-partylr3) 
gen partyconv23=abs(partylr2-partylr3) 

*** Social distance

gen partysocdista1=Q47A1 if Q47A1!=.
replace partysocdista1=Q52A1 if Q52A1!=.
gen partysocdista2=Q47A2 if Q47A2!=.
replace partysocdista2=Q52A2 if Q52A2!=.
gen partysocdista3=Q47A3 if Q47A3!=.
replace partysocdista3=Q52A3 if Q52A3!=.

gen partysocdistb1=Q48A1 if Q48A1!=.
replace partysocdistb1=Q53A1 if Q53A1!=.
gen partysocdistb2=Q48A2 if Q48A2!=.
replace partysocdistb2=Q53A2 if Q53A2!=.
gen partysocdistb3=Q48A3 if Q48A3!=.
replace partysocdistb3=Q53A3 if Q53A3!=.

alpha partylike1 partysocdista1 partysocdistb1, gen( partydislike_index1)
alpha partylike2 partysocdista2 partysocdistb2, gen( partydislike_index2)
alpha partylike3 partysocdista3 partysocdistb3, gen( partydislike_index3)

gen partysocdist1=(partysocdista1+partysocdistb1)/2
gen partysocdist2=(partysocdista2+partysocdistb2)/2
gen partysocdist3=(partysocdista3+partysocdistb3)/2

pwcorr partylike1 partysocdist1
pwcorr partylike2 partysocdist2
pwcorr partylike3 partysocdist3

drop partysocdist1-partysocdist3

gen partyconvergelike1=abs(partydislike_index1-partydislike_index2)
gen partyconvergelike2=abs(partydislike_index1-partydislike_index3)
gen partyconvergelike3=abs(partydislike_index2-partydislike_index3)

tabstat partylike1 partylike3 partylike3 if treat3, by(lrself)

tabstat partylike2 partylike3  if treat3==0&idvotecat==1
tabstat partylike1 partylike3  if treat3==0&idvotecat==2
tabstat partylike1 partylike2  if treat3==0&idvotecat==3
tabstat partylike1 partylike2 partylike3 if treat3==0&idvotecat==4
tabstat partylike1 partylike2 partylike3 if treat3==0&idvotecat==5

*** Response order: like-dislike or left-right first after treatment
gen responseorder=0 if Q49A1!=.&Q49A1<13
replace responseorder=1 if Q50A1!=.&Q50A1<13

label define responseorder 0 "affectfirst" 1 "positionsfirst"
label values responseorder responseorder


*** Indicator: in party in treatment
gen inpartyincluded=0
replace inpartyincluded=1 if treat3==0&idvotecat<4
replace inpartyincluded=1 if treat3==1&(idvotecat==1|idvotecat==2)
replace inpartyincluded=1 if treat3==2&(idvotecat==1|idvotecat==3)
replace inpartyincluded=1 if treat3==3&(idvotecat==2|idvotecat==3)

*** power analysis follow-up
ttest partylike3 if (treat3==0|treat3==2), by(treat3)
ttest partylike3 if (treat3==0|treat3==2)&idvotecat==1, by(treat3)
ttest partylike3 if (treat3==0|treat3==2)&idvotecat!=3&lrself>=5&lrself<=9, by(treat3)

gen testgroup1=(idvotecat==1)
regress partylike3 i.treat3##i.testgroup1 if treat3==0|treat3==2
margins, dydx(treat3) at(testgroup1=(0 1))
margins, dydx(treat3) at(testgroup1=(0 1)) pwcompare


gen testgroup1b=(idvotecat==1) if idvotecat!=3
regress partylike3 i.treat3##i.testgroup1b if treat3==0|treat3==2
margins, dydx(treat3) at(testgroup1b=(0 1))
margins, dydx(treat3) at(testgroup1b=(0 1)) pwcompare


gen testgroup2=(lrself>=5&lrself<=9) if idvotecat!=3
regress partylike3 i.treat3##i.testgroup2 if treat3==0|treat3==2
margins, dydx(treat3) at(testgroup2=(0 1))
margins, dydx(treat3) at(testgroup2=(0 1)) pwcompare

ttest partylike1 if (treat3==0|treat3==2)&idvotecat==3, by(treat3)
ttest partylike2 if (treat3==0|treat3==2)&idvotecat==3, by(treat3)



pwcorr partylike3 idvotecat1 idvotecat3 treat3  if (treat3==0|treat3==2)
gen ovp_x_treat3=idvotecat1*treat3
gen fpo_x_treat3=idvotecat3*treat3
pwcorr partylike3 idvotecat1 idvotecat3 treat3 ovp_x_treat3 fpo_x_treat3 if (treat3==0|treat3==2)
gen crid = .
replace crid = 1 if idvotecat!=3&lrself>=5&lrself<=9
replace crid = 0 if idvotecat!=3&lrself<5
gen crid_x_treat= crid*treat3
pwcorr partylike3  treat3 crid crid_x_treat if (treat3==0|treat3==2)

*****

reshape long partylike partylr  partysocdista partysocdistb id vote ppc , i(U0)

replace partylike=-(partylike-10)



rename _j party

label define party 1 "OeVP" 2 "SPOe" 3 "FPOe"
label values party party


gen partysocdist=(partysocdista+partysocdistb)/2
alpha partylike partysocdista partysocdistb, gen( partylike_index) 
gen partydist=abs(partylr-lrself)

gen helpsample=(idvotecat==party)
gen help=abs(lrself-partylr) if helpsample==1
bys U0: egen inpartydist=max(help) 
drop help helpsample

gen treat_stack_v2=0 if treat3==0
replace treat_stack_v2=1 if treat3==1&(party==1|party==2)
replace treat_stack_v2=1 if treat3==2&(party==1|party==3)
replace treat_stack_v2=1 if treat3==3&(party==2|party==3)
gen treat_stack_pers=treat_stack_v2
replace treat_stack_pers=2 if treat_stack_v2==1&personal==2

label define treat 0 "control" 1 "coalition signals treatment", replace
label values treat_stack_v2 treat

gen indic=1 if party==1&idvotecat==2
replace indic=2 if party==1&idvotecat==3
replace indic=3 if party==2&idvotecat==1
replace indic=4 if party==2&idvotecat==3
replace indic=5 if party==3&idvotecat==1
replace indic=6 if party==3&idvotecat==2

gen partyconv=partyconv12 if indic==1
replace partyconv=partyconv13 if indic==2
replace partyconv=partyconv12 if indic==3
replace partyconv=partyconv23 if indic==4
replace partyconv=partyconv13 if indic==5
replace partyconv=partyconv23 if indic==6


label define group 1 "ÖVP by SPÖ" 2 "ÖVP by FPÖ" 3 "SPÖ by ÖVP" 4 "SPÖ by FPÖ" 5 "FPÖ by ÖVP" 6 "FPÖ by SPÖ", replace
label values indic group




gen indic_outparty=1 if party==1&idvotecat==2
replace indic_outparty=2 if party==1&idvotecat==3
replace indic_outparty=3 if party==2&idvotecat==1
replace indic_outparty=4 if party==2&idvotecat==3
replace indic_outparty=5 if party==3&idvotecat==1
replace indic_outparty=6 if party==3&idvotecat==2
replace indic_outparty=7 if party==1&idvotecat==4
replace indic_outparty=8 if party==2&idvotecat==4
replace indic_outparty=9 if party==3&idvotecat==4
replace indic_outparty=10 if party==1&idvotecat==5
replace indic_outparty=11 if party==2&idvotecat==5
replace indic_outparty=12 if party==3&idvotecat==5


label define outparty 1 "ÖVP by SPÖ" 2 "ÖVP by FPÖ" 3 "SPÖ by ÖVP" 4 "SPÖ by FPÖ" 5 "FPÖ by ÖVP" 6 "FPÖ by SPÖ" 7 "ÖVP by Other" 8 "SPÖ by Other" 9 "FPÖ by Other" 10 "ÖVP by no id"  11 "SPÖ by no id" 12 "FPÖ by no id", replace
label values indic_outparty outparty

save "AP Katrin Markus/data/prepared_data.dta", replace
